#!/bin/bash
LANG=en_US.utf8
echo "亲测所有安装过程将持续30~40分钟，请耐心等待，喝杯咖啡什么的............"
echo "当然，视机器的相关配置而定！"
echo "开始安装cmake和g++ ........."
sleep 3
echo "----------------------------------"
cd cmake_g++
rpm -ivh *.rpm --force --nodeps

echo "添加环境变量...."
export PATH=$PATH:/usr/local/bin
export PATH=$PATH:/usr/bin
echo "cmake和 g++安装成功"
sleep 1
echo "开始ffmpeg ............"
sleep 3
echo "----------------------------------"
cd ..
cd ffmpeg
echo "安装ffmpeg使用汇编指令所依赖的yasm"
tar zxvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install

cd ..
tar -xvf ffmpeg-0.8.15.tar.bz2
cd ffmpeg-0.8.15
echo "正在对即将安装的软件进行配置，检查当前的环境是否满足要安装软件的依赖关系"
sleep 3
./configure --enable-shared --prefix=/usr/local/ffmpeg
make
make install
cp /usr/local/ffmpeg/lib/libavcodec.so libavformat.so libavutil.so  /usr/lib
cp /usr/local/ffmpeg/include/* /usr/include



echo "/usr/local/ffmpeg/lib/" >> /etc/ld.so.conf
/sbin/ldconfig
export PATH=/usr/local/ffmpeg/bin/:$PATH
env

echo "export PATH=/usr/local/ffmpeg/bin/:$PATH" >>/etc/profile
source /etc/profile
ffmpeg -v

echo "ffmpeg安装成功......"
sleep 2

#此处需重启
cd ..
cd ..

echo "开始安装gtk ........."
sleep 3
echo "----------------------------------"
cd gtk_install

rpm -ivh xorg-x11-proto-devel-7.7-13.el6.noarch.rpm 
rpm -Uvh freetype-2.3.11-17.el6.x86_64.rpm 
rpm -Uvh fontconfig-2.8.0-5.el6.x86_64.rpm 
rpm -Uvh glib2-2.28.8-5.el6.x86_64.rpm
rpm -ivh glib2-devel-2.28.8-5.el6.x86_64.rpm 
rpm -Uvh libpng-1.2.49-2.el6_7.x86_64.rpm
rpm -Uvh libxcb-1.11-2.el6.x86_64.rpm 
rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm  
rpm -ivh freetype-devel-2.3.11-17.el6.x86_64.rpm 
rpm -ivh fontconfig-devel-2.8.0-5.el6.x86_64.rpm
rpm -ivh libpng-devel-1.2.49-2.el6_7.x86_64.rpm
rpm -Uvh pixman-0.32.8-1.el6.x86_64.rpm
rpm -ivh pixman-devel-0.32.8-1.el6.x86_64.rpm
rpm -ivh atk-devel-1.30.0-1.el6.x86_64.rpm 
rpm -ivh libXau-devel-1.0.6-4.el6.x86_64.rpm
rpm -ivh libxcb-devel-1.11-2.el6.x86_64.rpm 
rpm -ivh autoconf-2.63-5.1.el6.noarch.rpm 
rpm -ivh automake-1.11.1-4.el6.noarch.rpm 
#转折点
echo "此处采取强制安装，忽视依赖性关系，暂不知有没有问题"
sleep 3
rpm -Uvh libX11-common-1.6.3-2.el6.noarch.rpm --force --nodeps
rpm -Uvh libX11-1.6.3-2.el6.x86_64.rpm 
rpm -ivh libX11-devel-1.6.3-2.el6.x86_64.rpm 
rpm -Uvh libXrender-0.9.8-2.1.el6_8.1.x86_64.rpm
rpm -Uvh libXext-1.3.3-1.el6.x86_64.rpm 
rpm -ivh libXext-devel-1.3.3-1.el6.x86_64.rpm
rpm -ivh libXrender-devel-0.9.8-2.1.el6_8.1.x86_64.rpm

rpm -Uvh cairo-1.8.8-6.el6_6.x86_64.rpm 

rpm -Uvh libXfixes-5.0.1-2.1.el6.x86_64.rpm 


rpm -ivh libXfixes-devel-5.0.1-2.1.el6.x86_64.rpm 

rpm -Uvh libXcursor-1.1.14-2.1.el6.x86_64.rpm 
rpm -Uvh libXi-1.7.4-1.el6.x86_64.rpm 
rpm -Uvh libXinerama-1.1.3-2.1.el6.x86_64.rpm
rpm -Uvh libXrandr-1.4.2-1.el6.x86_64.rpm
#转折点
echo "此处采取强制安装，忽视依赖性关系，暂不知有没有问题"
sleep 3
rpm -ivh gdk-pixbuf2-2.24.1-6.el6_7.x86_64.rpm --force --nodeps

rpm -ivh cairo-devel-1.8.8-6.el6_6.x86_64.rpm
rpm -Uvh libXft-2.3.2-1.el6.x86_64.rpm 
rpm -Uvh pango-1.28.1-11.el6.x86_64.rpm
rpm -Uvh gtk2-2.24.23-8.el6.x86_64.rpm 
rpm -Uvh libXft-devel-2.3.2-1.el6.x86_64.rpm
rpm -Uvh pango-devel-1.28.1-11.el6.x86_64.rpm
rpm -ivh gdk-pixbuf2-devel-2.24.1-6.el6_7.x86_64.rpm 

rpm -Uvh libXrandr-devel-1.4.2-1.el6.x86_64.rpm 
rpm -Uvh libXinerama-devel-1.1.3-2.1.el6.x86_64.rpm
rpm -Uvh libXi-devel-1.7.4-1.el6.x86_64.rpm
rpm -Uvh libXcursor-devel-1.1.14-2.1.el6.x86_64.rpm 
rpm -Uvh libXcomposite-devel-0.4.3-4.el6.x86_64.rpm
rpm -ivh gtk2-devel-2.24.23-8.el6.x86_64.rpm
rpm -ivh gtk+extra-2.1.1-13.el6.x86_64.rpm 
rpm -ivh gtk+extra-devel-2.1.1-13.el6.x86_64.rpm 
echo "gtk安装成功........"
sleep 3

cd ..
echo "开始安装opencv2.4.13 ........."
sleep 3
echo "----------------------------------"
unzip opencv-2.4.13.zip
cd opencv-2.4.13
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
make install

echo "正在配置opencv的相关环境变量等........"
echo "/usr/local/lib">> /etc/ld.so.conf
sudo /sbin/ldconfig
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH" >> /etc/bashrc

echo "正在将配置写入缓存......"
source /etc/bashrc
echo "正在更新数据库........"
sudo updatedb

echo "正在测试是否安装成功........"
echo "若出现两张图片，即为成功安装opencv"
echo "-------------------"
echo "安装成功后，部分配置需重启方能生效，请在安装成功后重启！！！"
echo "-------------------"
sleep 5
cd ..
cd samples/c
./build_all.sh
./find_obj

